package cn.kent.high.juc.lock.lockSupport;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.LockSupport;

public class LockSupportTest {
    public static void main(String[] args) throws InterruptedException {
        // System.out.println("begin park!");
        // // LockSupport.park(); // 将当前线程挂起
        //
        // // 使当前线程获取到关联许可证
        // LockSupport.unpark(Thread.currentThread());
        // LockSupport.park(); // 再次调用park方法
        // System.out.println("end park!");

        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("child thread begin pack!");
                // 调用pack方法，挂起自己，只有被中断才会退出循环
                while (!Thread.currentThread().isInterrupted()) {
                    LockSupport.park();
                }
                System.out.println("child thread unpack!");
            }
        });

        thread.start();
        Thread.sleep(1000);
        System.out.println("child thread begin unpack!");
        thread.interrupt();
        // // 让子线程拥有关联许可证
        // LockSupport.unpark(thread);
    }
}
